PCI: consolidate interface for adding devices
authorJan Beulich <jbeulich@novell.com>
Tue, 19 Jul 2011 13:14:08 +0000 (14:14 +0100)
committerJan Beulich <jbeulich@novell.com>
Tue, 19 Jul 2011 13:14:08 +0000 (14:14 +0100)
The functionality of pci_add_device_ext() can be easily folded into
pci_add_device(), and eliminates the need to change two functions for
future adjustments.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
xen/arch/ia64/xen/hypercall.c
xen/arch/x86/physdev.c
xen/drivers/passthrough/pci.c
xen/include/xen/pci.h

index 59035f53bd4e34c25c0a0d58bdd12bab526a2935..0aa4b452c35962d13fae15f48e4214d49f21ab6f 100644 (file)
@@ -665,8 +665,8 @@ long do_physdev_op(int cmd, XEN_GUEST_HANDLE(void) arg)
         if ( copy_from_guest(&manage_pci, arg, 1) != 0 )
             break;
 
-        ret = pci_add_device(manage_pci.bus, manage_pci.devfn);
-            break;
+        ret = pci_add_device(manage_pci.bus, manage_pci.devfn, NULL);
+        break;
     }
 
     case PHYSDEVOP_manage_pci_remove: {
@@ -698,10 +698,10 @@ long do_physdev_op(int cmd, XEN_GUEST_HANDLE(void) arg)
         pdev_info.is_virtfn = manage_pci_ext.is_virtfn;
         pdev_info.physfn.bus = manage_pci_ext.physfn.bus;
         pdev_info.physfn.devfn = manage_pci_ext.physfn.devfn;
-        ret = pci_add_device_ext(manage_pci_ext.bus,
-                                 manage_pci_ext.devfn,
-                                 &pdev_info);
-            break;
+        ret = pci_add_device(manage_pci_ext.bus,
+                             manage_pci_ext.devfn,
+                             &pdev_info);
+        break;
     }
 
     default:
index dccabe7a11443c1d2f0886b1635d67a1915099e7..4b0f4031e6a7396326d16ae5f87b2b1b85de6f56 100644 (file)
@@ -479,7 +479,7 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE(void) arg)
         if ( copy_from_guest(&manage_pci, arg, 1) != 0 )
             break;
 
-        ret = pci_add_device(manage_pci.bus, manage_pci.devfn);
+        ret = pci_add_device(manage_pci.bus, manage_pci.devfn, NULL);
         break;
     }
 
@@ -516,9 +516,9 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE(void) arg)
         pdev_info.is_virtfn = manage_pci_ext.is_virtfn;
         pdev_info.physfn.bus = manage_pci_ext.physfn.bus;
         pdev_info.physfn.devfn = manage_pci_ext.physfn.devfn;
-        ret = pci_add_device_ext(manage_pci_ext.bus,
-                                 manage_pci_ext.devfn,
-                                 &pdev_info);
+        ret = pci_add_device(manage_pci_ext.bus,
+                             manage_pci_ext.devfn,
+                             &pdev_info);
         break;
     }
 
index f3e4113e54e2a5bc6637ae9cd8d797774d9ebea8..7f7021927347b044961fc87ec4cf80fc8c3f6a29 100644 (file)
@@ -143,16 +143,29 @@ void pci_enable_acs(struct pci_dev *pdev)
     pci_conf_write16(bus, dev, func, pos + PCI_ACS_CTRL, ctrl);
 }
 
-int pci_add_device(u8 bus, u8 devfn)
+int pci_add_device(u8 bus, u8 devfn, const struct pci_dev_info *info)
 {
     struct pci_dev *pdev;
+    const char *pdev_type;
     int ret = -ENOMEM;
 
+    if (!info)
+        pdev_type = "device";
+    else if (info->is_extfn)
+        pdev_type = "extended function";
+    else if (info->is_virtfn)
+        pdev_type = "virtual function";
+    else
+        return -EINVAL;
+
     spin_lock(&pcidevs_lock);
     pdev = alloc_pdev(bus, devfn);
     if ( !pdev )
         goto out;
 
+    if ( info )
+        pdev->info = *info;
+
     ret = 0;
     if ( !pdev->domain )
     {
@@ -170,8 +183,8 @@ int pci_add_device(u8 bus, u8 devfn)
 
 out:
     spin_unlock(&pcidevs_lock);
-    printk(XENLOG_DEBUG "PCI add device %02x:%02x.%x\n", bus,
-           PCI_SLOT(devfn), PCI_FUNC(devfn));
+    printk(XENLOG_DEBUG "PCI add %s %02x:%02x.%x\n", pdev_type,
+           bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
     return ret;
 }
 
@@ -198,51 +211,6 @@ int pci_remove_device(u8 bus, u8 devfn)
     return ret;
 }
 
-int pci_add_device_ext(u8 bus, u8 devfn, struct pci_dev_info *info)
-{
-    int ret;
-    char *pdev_type;
-    struct pci_dev *pdev;
-
-    if (info->is_extfn)
-        pdev_type = "Extended Function";
-    else if (info->is_virtfn)
-        pdev_type = "Virtual Function";
-    else
-        return -EINVAL;
-
-
-    ret = -ENOMEM;
-    spin_lock(&pcidevs_lock);
-    pdev = alloc_pdev(bus, devfn);
-    if ( !pdev )
-        goto out;
-
-    pdev->info = *info;
-
-    ret = 0;
-    if ( !pdev->domain )
-    {
-        pdev->domain = dom0;
-        ret = iommu_add_device(pdev);
-        if ( ret )
-        {
-            pdev->domain = NULL;
-            goto out;
-        }
-
-        list_add(&pdev->domain_list, &dom0->arch.pdev_list);
-        pci_enable_acs(pdev);
-    }
-
-out:
-    spin_unlock(&pcidevs_lock);
-    printk(XENLOG_DEBUG "PCI add %s %02x:%02x.%x\n", pdev_type,
-           bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
-
-    return ret;
-}
-
 static int pci_clean_dpci_irq(struct domain *d,
                               struct hvm_pirq_dpci *pirq_dpci, void *arg)
 {
index 56355c79b9c52bbf9d2f4adf5f208fd22bf3f7e2..6313c388a335ac53986ea1cc0092443815b99649 100644 (file)
@@ -86,9 +86,8 @@ struct pci_dev *pci_lock_pdev(int bus, int devfn);
 struct pci_dev *pci_lock_domain_pdev(struct domain *d, int bus, int devfn);
 
 void pci_release_devices(struct domain *d);
-int pci_add_device(u8 bus, u8 devfn);
+int pci_add_device(u8 bus, u8 devfn, const struct pci_dev_info *);
 int pci_remove_device(u8 bus, u8 devfn);
-int pci_add_device_ext(u8 bus, u8 devfn, struct pci_dev_info *info);
 struct pci_dev *pci_get_pdev(int bus, int devfn);
 struct pci_dev *pci_get_pdev_by_domain(struct domain *d, int bus, int devfn);